package com.example.treasure_back.service;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.treasure_back.mapper.EssayMapper;
import com.example.treasure_back.model.EssayModel;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class EssayService {

    @Autowired
    EssayMapper essayMapper;

    public void addNum(Boolean is, Integer essayId){
        EssayModel essayModel = essayMapper.selectById(essayId);
        if(is){
            essayModel.setLikeNum(essayModel.getLikeNum() + 1);
        }
        else {
            essayModel.setDislikeNum(essayModel.getDislikeNum() + 1);
        }
        essayMapper.updateById(essayModel);
    }

    public void reduceNum(Boolean is, Integer essayId){
        EssayModel essayModel = essayMapper.selectById(essayId);
        if(is){
            essayModel.setLikeNum(essayModel.getLikeNum() - 1);
        }
        else {
            essayModel.setDislikeNum(essayModel.getDislikeNum() - 1);
        }
        essayMapper.updateById(essayModel);
    }



}
